-- Retribution
local vCount
function ccR_Paladin_3()
	-- Target Count
	vCount = ccrTargetCount(10)
	-- Level Detection
	if ccrPlayerLevel() >= 10 and ccrPlayerLevel() <= 89 then Paladin_Retribution_10_89() end
end

function Paladin_Retribution_10_89()

	-- Functions.lua
	ccR_Paladin_SealSwitching()	

	-- Talents.lua
		-- 30
		ccR_Paladin_HammerOfJustice()	
		-- 45
		ccR_Paladin_SelflessHealer()
		-- 75
		ccR_Paladin_HolyAvenger()

	-- Abilities.lua
	ccR_Paladin_LayOnHands()
	ccR_Paladin_DivineShield()
	ccR_Paladin_Cleanse()
	ccR_Paladin_DivineProtection()
	ccR_Paladin_Rebuke()
	ccR_Paladin_HandOfProtection()
	ccR_Paladin_HandOfFreedom()
	ccR_Paladin_Blessing_of_Kings()
	ccR_Paladin_Avenging_Wrath()
	ccR_Paladin_Guardian_of_Ancient_Kings()
	ccR_Paladin_Hammer_Of_Wrath()
	ccR_Paladin_Inquisition()
	ccR_Paladin_Word_of_Glory()

	-- Rotation
	if ccrPlayerHasSpell(DIVINE_STORM)
	and ccrPlayerHasSpell(HAMMER_OF_THE_RIGHTEOUS)
	then
		-- Single Target Rotation
		if (ccRS.Auto_AoE and (vCount >= 1 and vCount <= ccRS.Paladin_3_SingleTargetCount))
		or (ccrTargetIsBoss() and ccRS.Auto_AoE_Ignore_On_Boss)
		or (not ccRS.Auto_AoE and not ccRS.Manual_AoE)
		then
			ccR_Paladin_Exorcism()
			ccR_Paladin_Templars_Verdict()
			ccR_Paladin_Crusader_Strike()
			ccR_Paladin_Judgment()
			return
		end

		-- AoE Rotation
		if (ccRS.Auto_AoE and vCount >= ccRS.Paladin_3_AoECount)
		or (not ccRS.Auto_AoE and ccRS.Manual_AoE)
		then
			ccR_Paladin_Divine_Storm()
			ccR_Paladin_Hammer_of_the_Righteous()
			ccR_Paladin_Judgment()
			ccR_Paladin_Exorcism()
		end		
	else
		-- Single Target Rotation
		ccR_Paladin_Crusader_Strike()
		ccR_Paladin_Templars_Verdict()
		ccR_Paladin_Judgment()
		ccR_Paladin_Exorcism()
	end
end

function Paladin_Retribution_90()
	--[[
	http://www.simulationcraft.org/reports/Raid_T15H.html
	8	11.88	rebuke
	9	1.00	mogu_power_potion,if=(buff.bloodlust.react|(buff.ancient_power.up&buff.avenging_wrath.up)|target.time_to_die<=40)
	A	1.00	auto_attack
	B	7.99	inquisition,if=(buff.inquisition.down|buff.inquisition.remains<=2)&(holy_power>=3|target.time_to_die<holy_power*20|buff.divine_purpose.react)
	C	4.31	avenging_wrath,if=buff.inquisition.up
	D	3.01	guardian_of_ancient_kings,if=buff.inquisition.up
	E	0.00	holy_avenger,if=talent.holy_avenger.enabled&(buff.inquisition.up&holy_power<=2)
	F	7.80	use_item,name=reinbinders_fists,if=buff.inquisition.up&(buff.ancient_power.down|buff.ancient_power.stack=12)
	G	0.00	blood_fury
	H	0.00	berserking
	I	0.00	arcane_torrent
	J	7.80	execution_sentence,if=talent.execution_sentence.enabled&(buff.inquisition.up&(buff.ancient_power.down|buff.ancient_power.stack=12))
	K	0.00	lights_hammer,if=talent.lights_hammer.enabled&(buff.inquisition.up&(buff.ancient_power.down|buff.ancient_power.stack=12))
	L	0.00	divine_storm,if=active_enemies>=2&(holy_power=5|buff.divine_purpose.react|(buff.holy_avenger.up&holy_power>=3))
	M	0.00	divine_storm,if=buff.divine_crusader.react&holy_power=5
	N	32.53	templars_verdict,if=holy_power=5|buff.holy_avenger.up&holy_power>=3
	O	0.00	templars_verdict,if=buff.divine_purpose.react&buff.divine_purpose.remains<4
	P	70.32	hammer_of_wrath
	Q	39.98	wait,sec=cooldown.hammer_of_wrath.remains,if=cooldown.hammer_of_wrath.remains>0&cooldown.hammer_of_wrath.remains<=0.2
	R	0.00	divine_storm,if=buff.divine_crusader.react&buff.avenging_wrath.up
	S	25.03	templars_verdict,if=buff.avenging_wrath.up
	T	0.00	hammer_of_the_righteous,if=active_enemies>=4
	U	115.33	crusader_strike
	V	41.65	wait,sec=cooldown.crusader_strike.remains,if=cooldown.crusader_strike.remains>0&cooldown.crusader_strike.remains<=0.2
	W	0.00	exorcism,if=active_enemies>=2&active_enemies<=4&set_bonus.tier15_2pc_melee&glyph.mass_exorcism.enabled
	X	66.06	judgment
	Y	19.74	wait,sec=cooldown.judgment.remains,if=cooldown.judgment.remains>0&cooldown.judgment.remains<=0.2
	Z	0.00	divine_storm,if=buff.divine_crusader.react
	a	0.00	templars_verdict,if=buff.divine_purpose.react
	b	35.91	exorcism
	c	4.36	wait,sec=cooldown.exorcism.remains,if=cooldown.exorcism.remains>0&cooldown.exorcism.remains<=0.2
	d	14.57	templars_verdict,if=buff.tier15_4pc_melee.up&active_enemies<4
	e	0.00	divine_storm,if=active_enemies>=2&buff.inquisition.remains>4
	f	14.88	templars_verdict,if=buff.inquisition.remains>4
	g	0.00	holy_prism,if=talent.holy_prism.enabled
	]]
	-- 8	11.88	rebuke
	if SpellIsReady(REBUKE)
	and ccrTargetIsCastingOrChanneling()
	and ccrTargetIsInteruptable()
	then
		-- Instantly interupt a channeled spell
		if ccrTargetIsChannelingSpell() then
			ccrCastAttack(REBUKE)
			return
		end;
		-- Interupt a cast at 1s or less
		if ccrTargetIsCastingSpell()
		and ccrTargetHasLeftOnCast(1)
		then
			ccrCastAttack(REBUKE)
			return
		end
		return
	end

	-- 9	1.00	mogu_power_potion,if=(buff.bloodlust.react|(buff.ancient_power.up&buff.avenging_wrath.up)|target.time_to_die<=40)
	if (
		ccrPlayerHasBuff(2825) -- Bloodlust
		or (ccrPlayerHasBuff(86700) and ccrPlayerHasBuff(AVENGING_WRATH)) -- Ancient Power + Avenging Wrath
		--or ccrTargetTimeToDie(40)
		)
	and GetItemCount(76095) > 0 -- Mogu Power Potion
	and IsUsableItem(76095) == 1 -- Mogu Power Potion
	then
		UseItemByName("Mogu Power Potion")
		return
	end

	-- A	1.00	auto_attack
	if Target then StartAttack() end

	-- B	7.99	inquisition,if=(buff.inquisition.down|buff.inquisition.remains<=2)&(holy_power>=3|target.time_to_die<holy_power*20|buff.divine_purpose.react)
	if SpellIsReady(INQUISITION)
	and (
		not ccrPlayerHasBuff(INQUISITION)
		or
		ccrPlayerHasBuffRemaining(INQUISITION,2)
		)
	and (
		ccrHolyPower() >= 3
		--or
		-- ccrTargetTimeToDie((ccrHolyPower()*20))
		or
		ccrPlayerHasBuff(DIVINE_PURPOSE)
		)
	then
		ccrCast(INQUISITION)
		return
	end

	-- C	4.31	avenging_wrath,if=buff.inquisition.up
	if SpellIsReady(AVENGING_WRATH)
	and ccrPlayerHasBuff(INQUISITION)
	then
		ccrCast(AVENGING_WRATH)
		return
	end

	-- D	3.01	guardian_of_ancient_kings,if=buff.inquisition.up
	if SpellIsReady(GUARDIAN_OF_ANCIENT_KINGS)
	and	ccrPlayerHasBuff(INQUISITION)
	and ccrValidTarget()
	then
		ccrCast(GUARDIAN_OF_ANCIENT_KINGS)
		return
	end

	-- E	0.00	holy_avenger,if=talent.holy_avenger.enabled&(buff.inquisition.up&holy_power<=2)
	if SpellIsReady(HOLY_AVENGER)
	and ccrPlayerHasBuff(INQUISITION)
	and ccrHolyPower() <= 2
	then
		ccrCast(HOLY_AVENGER)
		return
	end

	-- F	7.80	use_item,name=reinbinders_fists,if=buff.inquisition.up&(buff.ancient_power.down|buff.ancient_power.stack=12)
	-- WTF?

	-- G	0.00	blood_fury
	if SpellIsReady(20572) then
		ccrCast(20572)
		return
	end

	-- H	0.00	berserking
	if SpellIsReady(26297) then
		ccrCast(26297)
		return
	end

	-- I	0.00	arcane_torrent
	if SpellIsReady(28730) then
		ccrCast(28730)
		return
	end

	-- J	7.80	execution_sentence,if=talent.execution_sentence.enabled&(buff.inquisition.up&(buff.ancient_power.down|buff.ancient_power.stack=12))
	if SpellIsReady(EXECUTION_SENTENCE)
	and SpellCanAttack(EXECUTION_SENTENCE)
	and (
		ccrPlayerHasBuff(INQUISITION) 
		and 
			(
				not ccrPlayerHasBuff(86700) or ccrPlayerHasBuffStacks(86700, 12)
			)
		)
	then
		ccrCastAttack(EXECUTION_SENTENCE)
		return
	end

	-- K	0.00	lights_hammer,if=talent.lights_hammer.enabled&(buff.inquisition.up&(buff.ancient_power.down|buff.ancient_power.stack=12))
	if SpellIsReady(LIGHTS_HAMMER)
	and SpellCanAttack(LIGHTS_HAMMER)
	and (
		ccrPlayerHasBuff(INQUISITION) 
		and 
			(
				not ccrPlayerHasBuff(86700) or ccrPlayerHasBuffStacks(86700, 12)
			)
		)
	then
		ccrCastAttack(LIGHTS_HAMMER)
		return
	end	

	-- L	0.00	divine_storm,if=active_enemies>=2&(holy_power=5|buff.divine_purpose.react|(buff.holy_avenger.up&holy_power>=3))
	if SpellIsReady(DIVINE_STORM)
	and vCount >= 2
	and (
		ccrHolyPower() == 5
		or
		ccrPlayerHasBuff(DIVINE_PURPOSE)
		or
			(
				ccrPlayerHasBuff(HOLY_AVENGER)
				and
				ccrHolyPower() >= 3
			)
		)
	then
		ccrCast(DIVINE_STORM)
		return
	end

	-- M	0.00	divine_storm,if=buff.divine_crusader.react&holy_power=5
	if SpellIsReady(DIVINE_STORM)
	and ccrPlayerHasBuff(DIVINE_CRUSADER)
	and ccrHolyPower() == 5
	then
		ccrCast(DIVINE_STORM)
		return
	end

	-- N	32.53	templars_verdict,if=holy_power=5|buff.holy_avenger.up&holy_power>=3
	if SpellCanAttack(TEMPLARS_VERDICT)
	and (
		ccrHolyPower() == 5
		or
			(
				ccrPlayerHasBuff(HOLY_AVENGER)
				and
				ccrHolyPower() >= 3
			)
		)
	then
		ccrCastAttack(TEMPLARS_VERDICT)
		return
	end

	--[[
	O	0.00	templars_verdict,if=buff.divine_purpose.react&buff.divine_purpose.remains<4
	P	70.32	hammer_of_wrath
	Q	39.98	wait,sec=cooldown.hammer_of_wrath.remains,if=cooldown.hammer_of_wrath.remains>0&cooldown.hammer_of_wrath.remains<=0.2
	R	0.00	divine_storm,if=buff.divine_crusader.react&buff.avenging_wrath.up
	S	25.03	templars_verdict,if=buff.avenging_wrath.up
	T	0.00	hammer_of_the_righteous,if=active_enemies>=4
	U	115.33	crusader_strike
	V	41.65	wait,sec=cooldown.crusader_strike.remains,if=cooldown.crusader_strike.remains>0&cooldown.crusader_strike.remains<=0.2
	W	0.00	exorcism,if=active_enemies>=2&active_enemies<=4&set_bonus.tier15_2pc_melee&glyph.mass_exorcism.enabled
	X	66.06	judgment
	Y	19.74	wait,sec=cooldown.judgment.remains,if=cooldown.judgment.remains>0&cooldown.judgment.remains<=0.2
	Z	0.00	divine_storm,if=buff.divine_crusader.react
	a	0.00	templars_verdict,if=buff.divine_purpose.react
	b	35.91	exorcism
	c	4.36	wait,sec=cooldown.exorcism.remains,if=cooldown.exorcism.remains>0&cooldown.exorcism.remains<=0.2
	d	14.57	templars_verdict,if=buff.tier15_4pc_melee.up&active_enemies<4
	e	0.00	divine_storm,if=active_enemies>=2&buff.inquisition.remains>4
	f	14.88	templars_verdict,if=buff.inquisition.remains>4
	g	0.00	holy_prism,if=talent.holy_prism.enabled
	]]

end